package com.Bigbluebook.Service;

import com.Bigbluebook.api.ApiConstants;
import com.Bigbluebook.entity.Star;
import com.Bigbluebook.entity.StarStatus;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class StarApiService {
    private StarService starService;
    private Retrofit retrofit;
    private Gson gson;

    public StarApiService() {
        gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
                .create();
        retrofit = new Retrofit.Builder()
                .baseUrl(ApiConstants.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
        starService = retrofit.create(StarService.class);
    }

    public void starPost(Star star, Callback<Star> callback) {
        Call<Star> call = starService.starPost(star);
        call.enqueue(callback);
    }

    public void getStarsForPost(int postId, Callback<List<Star>> callback) {
        Call<List<Star>> call = starService.getStarsForPost(postId);
        call.enqueue(callback);
    }

    public void unstarPost(int starId, Callback<Void> callback) {
        Call<Void> call = starService.unstarPost(starId);
        call.enqueue(callback);
    }

    public void checkLikeStatus(int postId, int userId, Callback<StarStatus> callback) {
        Call<StarStatus> call = starService.checkLikeStatus(postId, userId);
        call.enqueue(callback);
    }
}
